package com.yuneec.droneservice.command;

import com.yuneec.droneservice.model.Aircraft;
import com.yuneec.droneservice.request.IResponse;
import com.yuneec.droneservice.utils.ByteUtils;

import java.util.Arrays;

/**
 * Created by gjw on 2017/3/27.
 */

public class GetAircraftInfo extends BaseCommand {

    public GetAircraftInfo() {
        super(MAV_RC_COMMAND.MAV_RC_CMD_GET_BIND_INFO);
    }


    @Override
    public IResponse<Aircraft> toResponse(byte[] data, int off, int len) {
        int code = data[off + 1] & 0xff;
        IResponse<Aircraft> response = new IResponse(ids(), code);
        if (code == MAV_RC_ERROR_CODE.MAV_RC_ERR_SUCCESS) {
            Aircraft aircraft = new Aircraft();
            aircraft.setId(ByteUtils.byteArrayToInt(Arrays.copyOfRange(data, off + 2, 6), IS_BIGENDIAN));
            if (aircraft.getId() > 0) {
                response.setParam(aircraft);
            }
        }
        return response;
    }
}
